package com.huaboot.generator.service;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaboot.generator.entity.TableFieldEntity;
import com.huaboot.generator.mapper.TableFieldMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Author ff
 * @Date 2023/8/13 7:17 下午
 * @Version 1.0
 */
@Service
public class TableFieldServiceImpl extends ServiceImpl<TableFieldMapper , TableFieldEntity> implements  TableFieldService{

    @Autowired
    private TableFieldMapper tableFieldMapper;


    @Override
    public List<TableFieldEntity> getTableFieldListByTableId(Long tableId) {
        LambdaQueryWrapper<TableFieldEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TableFieldEntity::getTableId, tableId);
        return tableFieldMapper.selectList(queryWrapper);

    }

    @Override
    public void updateTableField(Long tableId, List<TableFieldEntity> tableFieldList) {
        // 更新字段数据
        int sort = 0;
        for (TableFieldEntity tableField : tableFieldList) {
            tableField.setSort(sort++);
            this.updateById(tableField);
        }
    }

    @Override
    public Set<String> getList() {

        return tableFieldMapper.getList();
    }
}
